package com.pdg.dungeondelver.client;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;

import com.pdg.dungeondelver.configuration.Configuration;

public class BaseGameState implements GameState{
	private static final float FPS_X = 0;
	private static final float FPS_Y = 0;
	private static final String FORMAT_FPS = "FPS: %d";
	private Configuration configuration;
	public Configuration getConfiguration(){
		return configuration;
	}
	private boolean displayDebug = false;
	private boolean handlingInput;
	private Client client;
	private States state;
	public boolean getDisplayDebug(){
		return displayDebug;
	}
	public void setDisplayDebug(boolean value){
		displayDebug = value;
	}
	public States getState(){
		return state;
	}
	public BaseGameState(Configuration theConfiguration,Client theClient, States theState){
		configuration = theConfiguration;
		state = theState;
		client = theClient;
	}
	public void enter(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		setHandlingInput(true);
	}
	private void setHandlingInput(boolean b) {
		handlingInput = b;
		
	}
	public void init(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
	}

	public void leave(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		setHandlingInput(false);
	}
	@Override
	public void inputEnded() {
	}
	@Override
	public void inputStarted() {
	}
	@Override
	public boolean isAcceptingInput() {
		return getHandlingInput();
	}
	private boolean getHandlingInput() {
		return handlingInput;
	}
	@Override
	public void setInput(Input arg0) {
	}
	@Override
	public void keyPressed(int arg0, char arg1) {
		if(arg0==Input.KEY_F3){
			setDisplayDebug(!getDisplayDebug());
		}
	}
	@Override
	public void keyReleased(int arg0, char arg1) {
	}
	@Override
	public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
	}
	@Override
	public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
	}
	@Override
	public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
	}
	@Override
	public void mousePressed(int arg0, int arg1, int arg2) {
	}
	@Override
	public void mouseReleased(int arg0, int arg1, int arg2) {
	}
	@Override
	public void mouseWheelMoved(int arg0) {
	}
	@Override
	public void controllerButtonPressed(int arg0, int arg1) {
	}
	@Override
	public void controllerButtonReleased(int arg0, int arg1) {
	}
	@Override
	public void controllerDownPressed(int arg0) {
	}
	@Override
	public void controllerDownReleased(int arg0) {
	}
	@Override
	public void controllerLeftPressed(int arg0) {
	}
	@Override
	public void controllerLeftReleased(int arg0) {
	}
	@Override
	public void controllerRightPressed(int arg0) {
	}
	@Override
	public void controllerRightReleased(int arg0) {
	}
	@Override
	public void controllerUpPressed(int arg0) {
	}
	@Override
	public void controllerUpReleased(int arg0) {
	}
	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
			throws SlickException {
		if(getDisplayDebug()){
			g.drawString(String.format(FORMAT_FPS,gc.getFPS()), FPS_X, FPS_Y);
		}
	}
	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta)
			throws SlickException {
	}
	
	public Client getClient(){
		return client;
	}
	@Override
	public int getID() {
		return getState().getIndex();
	}
}
